<template>
  <router-view></router-view>
</template>

<script setup>
import { onMounted, watch } from 'vue'
import { useAuthStore } from './store/auth'
import { useSettingsStore } from './store/settings'
import { storeToRefs } from 'pinia'

const authStore = useAuthStore()
const settingsStore = useSettingsStore()
const { settings } = storeToRefs(settingsStore)

// 监听设置变化并应用
watch(() => settings.value.interface?.theme, (newTheme) => {
  if (newTheme) {
    settingsStore.applyThemeSettings(newTheme)
  }
}, { deep: true })

onMounted(async () => {
  // 初始化认证状态
  await authStore.fetchUser()
  
  // 初始化设置
  if (authStore.isAuthenticated) {
    await settingsStore.initialize()
  } else {
    // 未登录时使用本地存储的设置
    settingsStore.loadLocalSettings()
  }
})
</script>
